<?php
/**
 * 主导航菜单组件
 */
    namespace app\commands\front;
    use app\libs\Method;
use yii\base\Widget;
    use yii;
    use app\modules\content\models\Ad;

	class NavWidget extends Widget  {
        public $session;
        public $now_path;
        public $controller;
        public $action;
        /**
         * 定义函数
         * */
        public function init()
        {//这个可以取侧边栏数
            $this->controller = Yii::$app->controller->id;
            $this->action = Yii::$app->controller->action->id;
            $this->url();
    }

        /**
         * 运行覆盖程序
         * */
        public function run(){
            $data = '这个可以取侧边栏数';
            $model = new Ad();
            $ad = $model->getAd(3);
            $userId = Yii::$app->session->get('userId');
            
            $userData= Yii::$app->session->get('userData');
            //公开课
            $openCourse = Method::curl_post_fix('https://live.viplgw.cn/api/room/open-course',['belong'=>10]);
            $openCourse = json_decode($openCourse,true)['data'];
            return $this->render('nav',['userId'=>$userId,'userData'=>$userData,'path'=>$this->now_path,'controller' => $this->controller,'action'=>$this->action, 'data'=>$data, 'ad'=>$ad,'openCourse'=>$openCourse]);
        }

        public function url(){
            $this->now_path=ltrim($_SERVER['REQUEST_URI'],'/');
        }

    }
?>

